import {ref, Ref} from "vue";
import axios from '@/utils/axios';
import {message} from "ant-design-vue";

class CementDeviceInfo {
  deviceId: number | null = null
  count: number | undefined
  diameter: number | null = null
}

export default ()=>{
  const cementDeviceViewInfo = ref({
    showModal:false
  })
  const cementDeviceInfo = <Ref<CementDeviceInfo>>ref(new CementDeviceInfo())

  // 获取水泥搅拌桩设备详细信息
  const getCementDeviceInfo = (deviceId:number, callback: Function|null = null)=>{
    cementDeviceInfo.value = new CementDeviceInfo();
    axios.post("/cement/findDeviceParameterByDeviceId",{deviceId:deviceId}).then((res:any)=>{
      if(res.success){
        Object.assign(cementDeviceInfo.value,res.data)
        console.log(cementDeviceInfo)

      }else{
        cementDeviceInfo.value.deviceId = deviceId
      }
      if(callback) callback()
    })
  }
  // 设置水泥搅拌桩设备详细信息
  const setCementDeviceInfo = (callback:Function|null = null)=>{
    axios.post("/cement/saveDeviceParameterByDeviceId",cementDeviceInfo.value).then((res:any)=>{
      if(res.success){
        console.log("***************Count***************")
        console.log(cementDeviceInfo.value.count)

        message.info("保存成功")
        if(callback) callback()
      }else{
        message.info(res.msg)
      }
    })
  }

  return {
    cementDeviceViewInfo,
    cementDeviceInfo,
    getCementDeviceInfo,
    setCementDeviceInfo

  }
}